import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:shopping_group/base/page_constance.dart';
import 'package:shopping_group/entity/rich_text_entity.dart';
import 'package:shopping_group/modle/login/ui/userxy_about_page.dart';
import 'package:shopping_group/modle/login/ui/userys_about_page.dart';
import 'package:shopping_group/modle/main/ui/bottom_menu_page.dart';
import 'package:shopping_group/res/colors.dart';
import 'package:shopping_group/res/dimens.dart';
import 'package:shopping_group/utils/route_util.dart';
import 'package:shopping_group/utils/shared_preferences_util.dart';
import 'package:shopping_group/utils/widget_utils.dart';

class YinsiDialogPage extends StatefulWidget {
  YinsiDialogPage({
    Key key,
  }) : super(key: key);

  @override
  _YinsiDialogPageState createState() => _YinsiDialogPageState();
}

class _YinsiDialogPageState extends State<YinsiDialogPage> {
  List<RichTextEntity> list = [];
  @override
  void initState() {
    super.initState();

    list
      ..add(RichTextEntity()
        ..backgroundColor = Colours.transparent
        ..title = '尊敬的用户您好，欢迎使用利正生活！\n\n'
        ..textColor = Colours.text_2222
        ..size = Dimens.FONT_SIZE_16)
      ..add(RichTextEntity()
        ..backgroundColor = Colours.transparent
        ..title = '请您在使用我们产品前，务必仔细阅读'
        ..textColor = Colours.text_2222
        ..size = Dimens.FONT_SIZE_16)
      ..add(RichTextEntity()
        ..backgroundColor = Colours.transparent
        ..title = '《利正生活注册协议》'
        ..textColor = Colours.themeColor
        ..size = Dimens.FONT_SIZE_16)
      ..add(RichTextEntity()
        ..backgroundColor = Colours.transparent
        ..title = '及'
        ..textColor = Colours.text_2222
        ..size = Dimens.FONT_SIZE_16)
      ..add(RichTextEntity()
        ..backgroundColor = Colours.transparent
        ..title = '《利正生活隐私协议》'
        ..textColor = Colours.themeColor
        ..size = Dimens.FONT_SIZE_16)
      ..add(RichTextEntity()
        ..backgroundColor = Colours.transparent
        ..title = '，特向您说明如下：\n'
        ..textColor = Colours.text_2222
        ..size = Dimens.FONT_SIZE_16)
      ..add(RichTextEntity()
        ..backgroundColor = Colours.transparent
        ..title = '1.为向您提供交易相关功能，我们会收集、使用必要的信息；\n'
        ..textColor = Colours.text_2222
        ..size = Dimens.FONT_SIZE_16)
      ..add(RichTextEntity()
        ..backgroundColor = Colours.transparent
        ..title = '2.基于您的授权，我们可能会获取您的位置等信息，您有权拒绝或取消授权；\n'
        ..textColor = Colours.text_2222
        ..size = Dimens.FONT_SIZE_16)
      ..add(RichTextEntity()
        ..backgroundColor = Colours.transparent
        ..title = '3.我们会采取业界先进的安全措施保护您的信息安全；\n'
        ..textColor = Colours.text_2222
        ..size = Dimens.FONT_SIZE_16)
      ..add(RichTextEntity()
        ..backgroundColor = Colours.transparent
        ..title = '4.未经您的同意，我们不会从第三方处获取、共享或向其提供您的信息；\n'
        ..textColor = Colours.text_2222
        ..size = Dimens.FONT_SIZE_16)
      ..add(RichTextEntity()
        ..backgroundColor = Colours.transparent
        ..title = '5.您可以查询、更正、删除您的个人信息，我们也提供账户销毁的渠道；\n'
        ..textColor = Colours.text_2222
        ..size = Dimens.FONT_SIZE_16);
  }

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        GestureDetector(
          onTap: () {
            // Navigator.of(context).pop();
          },
          child: Container(
            decoration: new BoxDecoration(
              color: Colours.transparent_25,
            ),
            alignment: Alignment.center,
          ),
        ),
        Container(
          margin: EdgeInsets.only(
              top: MediaQuery.of(context).size.height / 10,
              bottom: MediaQuery.of(context).size.height / 10,
              left: 32,
              right: 32),
          padding: EdgeInsets.symmetric(horizontal: 8),
          alignment: Alignment.center,
          decoration: BoxDecoration(
              border: Border.all(color: Colours.title_white, width: 0.0),
              borderRadius: BorderRadius.circular(10.0),
              color: Colours.title_white),
          child: Column(
            children: <Widget>[
              SizedBox(
                height: 8,
              ),
              WidgetUtils.getTextColorView(
                '温馨提示',
                Colours.text_2222,
                Dimens.FONT_SIZE_18,
                fontweight: FontWeight.w500,
              ),
              SizedBox(
                height: 8,
              ),
              Expanded(
                child: _contentView(),
              ),
              WidgetUtils.drawDivider(),
              SizedBox(
                height: 12,
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: <Widget>[
                  GestureDetector(
                    onTap: () {
                      SystemNavigator.pop();
                    },
                    child: WidgetUtils.getTextColorView(
                      '不同意',
                      Colours.text_2222,
                      Dimens.FONT_SIZE_16,
                    ),
                  ),
                  WidgetUtils.drawVerticalContainer(height: 24),
                  GestureDetector(
                    onTap: () {
                      SharedPreferencesUtil.addShare('firstYs', 'Y');
                      RouteUtil.pushNamedAndRemoveUntil(PageConstance.MAIN_PAGE);
                    },
                    child: WidgetUtils.getTextColorView(
                      '同意',
                      Colours.themeColor,
                      Dimens.FONT_SIZE_16,
                    ),
                  ),
                ],
              ),
              SizedBox(
                height: 12,
              ),
            ],
          ),
        ),
      ],
    );
  }

  Widget _contentView() {
    return SingleChildScrollView(
      scrollDirection: Axis.vertical,
      reverse: false,
      padding: EdgeInsets.all(0.0),
      physics: BouncingScrollPhysics(),
      child: WidgetUtils.getRichTextView(list, onCilekListener: (entity) {
        if (null != entity && entity is RichTextEntity) {
          if (entity.title.contains('注册协议')) {
            RouteUtil.goParameter(UserXyAboutPage());
          } else if (entity.title.contains('隐私协议')) {
            RouteUtil.goParameter(UserYsAboutPage());
          }
        }
      }),
    );
  }

  @override
  void dispose() {
    super.dispose();
  }
}
